package com.itlzh.mall.user.controller;

import com.itlzh.mall.common.entity.UserInfo;
import com.itlzh.mall.common.result.Result;
import com.itlzh.mall.user.service.IUserInfoService;
import org.mindrot.jbcrypt.BCrypt;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("user")
public class UserInfoController {
    /**
     * 用户注册
     */
    @Autowired
    private IUserInfoService  userInfoService;
    @PostMapping("/register")
    public Result register(@RequestBody UserInfo userInfo){
        //调用service层进行注册
        userInfo.setPassword(BCrypt.hashpw(userInfo.getPassword(), BCrypt.gensalt()));
        userInfoService.save(userInfo);
        return Result.success();
    }
    @PutMapping("/update")
    public Result update(@RequestBody UserInfo userInfo){
        userInfoService.updateById(userInfo);
        return Result.success();
    }

    @GetMapping("/queryById")
    public Result queryById( String id){
        return Result.success(userInfoService.getById(id));
    }


}
